/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * vistaProveedor.java
 *
 * Created on 25/03/2011, 02:31:38 PM
 */

package jcpcotizaciones.vista;

import java.sql.SQLException;
import java.text.DecimalFormat;
import java.util.Iterator;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JOptionPane;
import javax.swing.table.DefaultTableModel;
import jcpcotizaciones.Control.ControlProveedor;
import jcpcotizaciones.Modelo.Proveedor;

/**
 *
 * @author Vasquez
 */
public class vistaProveedor extends javax.swing.JFrame {

    /** Creates new form vistaProveedor */
    public vistaProveedor() {
        initComponents();
        listarProveedor();
    }
DefaultTableModel dtm = new DefaultTableModel();
    
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jd_eliminarProveedor = new javax.swing.JDialog();
        bt_jdEliminar = new javax.swing.JButton();
        jButton2 = new javax.swing.JButton();
        pisoProveedor = new jcMousePanel.jcMousePanel();
        jcMousePanel1 = new jcMousePanel.jcMousePanel();
        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        jLabel6 = new javax.swing.JLabel();
        tx_codigo = new javax.swing.JTextField();
        tx_cedula = new javax.swing.JTextField();
        tx_nombre = new javax.swing.JTextField();
        tx_direccion = new javax.swing.JTextField();
        tx_telefono = new javax.swing.JTextField();
        tx_email = new javax.swing.JTextField();
        jLabel7 = new javax.swing.JLabel();
        cb_tipo = new javax.swing.JComboBox();
        jcMousePanel2 = new jcMousePanel.jcMousePanel();
        bt_agregar = new javax.swing.JButton();
        bt_modificar = new javax.swing.JButton();
        bt_eliminar = new javax.swing.JButton();
        bt_limpiar = new javax.swing.JButton();
        jcMousePanel3 = new jcMousePanel.jcMousePanel();
        scroll = new javax.swing.JScrollPane();
        tabalproveedor = new javax.swing.JTable(dtm);
        bt_buscar = new javax.swing.JButton();
        tx_buscar = new javax.swing.JTextField();
        cb_buscarproveedor = new javax.swing.JComboBox();
        jcMousePanel4 = new jcMousePanel.jcMousePanel();

        jd_eliminarProveedor.setName("jd_eliminarProveedor"); // NOI18N

        org.jdesktop.application.ResourceMap resourceMap = org.jdesktop.application.Application.getInstance(jcpcotizaciones.JCPCOTIZACIONESApp.class).getContext().getResourceMap(vistaProveedor.class);
        bt_jdEliminar.setText(resourceMap.getString("bt_jdEliminar.text")); // NOI18N
        bt_jdEliminar.setName("bt_jdEliminar"); // NOI18N
        bt_jdEliminar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                bt_jdEliminarActionPerformed(evt);
            }
        });

        jButton2.setText(resourceMap.getString("jButton2.text")); // NOI18N
        jButton2.setName("jButton2"); // NOI18N
        jButton2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton2ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jd_eliminarProveedorLayout = new javax.swing.GroupLayout(jd_eliminarProveedor.getContentPane());
        jd_eliminarProveedor.getContentPane().setLayout(jd_eliminarProveedorLayout);
        jd_eliminarProveedorLayout.setHorizontalGroup(
            jd_eliminarProveedorLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jd_eliminarProveedorLayout.createSequentialGroup()
                .addContainerGap(212, Short.MAX_VALUE)
                .addComponent(bt_jdEliminar)
                .addGap(32, 32, 32)
                .addComponent(jButton2)
                .addContainerGap())
        );
        jd_eliminarProveedorLayout.setVerticalGroup(
            jd_eliminarProveedorLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jd_eliminarProveedorLayout.createSequentialGroup()
                .addContainerGap(266, Short.MAX_VALUE)
                .addGroup(jd_eliminarProveedorLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(bt_jdEliminar)
                    .addComponent(jButton2))
                .addContainerGap())
        );

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setName("Form"); // NOI18N

        pisoProveedor.setIcon(resourceMap.getIcon("pisoProveedor.icon")); // NOI18N
        pisoProveedor.setName("pisoProveedor"); // NOI18N

        jcMousePanel1.setBorder(javax.swing.BorderFactory.createTitledBorder(null, resourceMap.getString("jcMousePanel1.border.title"), javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, resourceMap.getFont("jcMousePanel1.border.titleFont"), resourceMap.getColor("jcMousePanel1.border.titleColor"))); // NOI18N
        jcMousePanel1.setIcon(resourceMap.getIcon("jcMousePanel1.icon")); // NOI18N
        jcMousePanel1.setName("jcMousePanel1"); // NOI18N

        jLabel1.setText(resourceMap.getString("jLabel1.text")); // NOI18N
        jLabel1.setName("jLabel1"); // NOI18N

        jLabel2.setText(resourceMap.getString("jLabel2.text")); // NOI18N
        jLabel2.setName("jLabel2"); // NOI18N

        jLabel3.setText(resourceMap.getString("jLabel3.text")); // NOI18N
        jLabel3.setName("jLabel3"); // NOI18N

        jLabel4.setText(resourceMap.getString("jLabel4.text")); // NOI18N
        jLabel4.setName("jLabel4"); // NOI18N

        jLabel5.setText(resourceMap.getString("jLabel5.text")); // NOI18N
        jLabel5.setName("jLabel5"); // NOI18N

        jLabel6.setText(resourceMap.getString("jLabel6.text")); // NOI18N
        jLabel6.setName("jLabel6"); // NOI18N

        tx_codigo.setFont(resourceMap.getFont("tx_codigo.font")); // NOI18N
        tx_codigo.setText(resourceMap.getString("tx_codigo.text")); // NOI18N
        tx_codigo.setCursor(new java.awt.Cursor(java.awt.Cursor.TEXT_CURSOR));
        tx_codigo.setEnabled(false);
        tx_codigo.setName("tx_codigo"); // NOI18N

        tx_cedula.setText(resourceMap.getString("tx_cedula.text")); // NOI18N
        tx_cedula.setName("tx_cedula"); // NOI18N

        tx_nombre.setText(resourceMap.getString("tx_nombre.text")); // NOI18N
        tx_nombre.setName("tx_nombre"); // NOI18N
        tx_nombre.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusLost(java.awt.event.FocusEvent evt) {
                tx_nombreFocusLost(evt);
            }
        });

        tx_direccion.setText(resourceMap.getString("tx_direccion.text")); // NOI18N
        tx_direccion.setName("tx_direccion"); // NOI18N
        tx_direccion.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusLost(java.awt.event.FocusEvent evt) {
                tx_direccionFocusLost(evt);
            }
        });

        tx_telefono.setText(resourceMap.getString("tx_telefono.text")); // NOI18N
        tx_telefono.setName("tx_telefono"); // NOI18N

        tx_email.setText(resourceMap.getString("tx_email.text")); // NOI18N
        tx_email.setName("tx_email"); // NOI18N
        tx_email.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusLost(java.awt.event.FocusEvent evt) {
                tx_emailFocusLost(evt);
            }
        });

        jLabel7.setText(resourceMap.getString("jLabel7.text")); // NOI18N
        jLabel7.setName("jLabel7"); // NOI18N

        cb_tipo.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Seleccione un tipo de Proveedor", "Impresión", "Papel", "Otros" }));
        cb_tipo.setName("cb_tipo"); // NOI18N

        javax.swing.GroupLayout jcMousePanel1Layout = new javax.swing.GroupLayout(jcMousePanel1);
        jcMousePanel1.setLayout(jcMousePanel1Layout);
        jcMousePanel1Layout.setHorizontalGroup(
            jcMousePanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jcMousePanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jcMousePanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jcMousePanel1Layout.createSequentialGroup()
                        .addGroup(jcMousePanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel1)
                            .addComponent(jLabel3)
                            .addComponent(jLabel2))
                        .addGap(8, 8, 8)
                        .addGroup(jcMousePanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(tx_nombre, javax.swing.GroupLayout.DEFAULT_SIZE, 154, Short.MAX_VALUE)
                            .addComponent(tx_cedula, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 154, Short.MAX_VALUE)
                            .addComponent(tx_codigo, javax.swing.GroupLayout.DEFAULT_SIZE, 154, Short.MAX_VALUE)))
                    .addGroup(jcMousePanel1Layout.createSequentialGroup()
                        .addGroup(jcMousePanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel4)
                            .addComponent(jLabel5)
                            .addComponent(jLabel6)
                            .addComponent(jLabel7))
                        .addGap(8, 8, 8)
                        .addGroup(jcMousePanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(tx_direccion, javax.swing.GroupLayout.DEFAULT_SIZE, 154, Short.MAX_VALUE)
                            .addComponent(tx_telefono, javax.swing.GroupLayout.DEFAULT_SIZE, 154, Short.MAX_VALUE)
                            .addComponent(tx_email, javax.swing.GroupLayout.DEFAULT_SIZE, 154, Short.MAX_VALUE)
                            .addComponent(cb_tipo, 0, 154, Short.MAX_VALUE))))
                .addContainerGap())
        );
        jcMousePanel1Layout.setVerticalGroup(
            jcMousePanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jcMousePanel1Layout.createSequentialGroup()
                .addGroup(jcMousePanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel1)
                    .addComponent(tx_codigo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jcMousePanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel3)
                    .addComponent(tx_cedula, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jcMousePanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(tx_nombre, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel2))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jcMousePanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel7)
                    .addComponent(cb_tipo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGroup(jcMousePanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(tx_direccion, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel4))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jcMousePanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(tx_telefono, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel5))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jcMousePanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(tx_email, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel6))
                .addContainerGap())
        );

        jcMousePanel2.setBorder(javax.swing.BorderFactory.createTitledBorder(null, resourceMap.getString("jcMousePanel2.border.title"), javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, resourceMap.getFont("jcMousePanel2.border.titleFont"), resourceMap.getColor("jcMousePanel2.border.titleColor"))); // NOI18N
        jcMousePanel2.setIcon(resourceMap.getIcon("jcMousePanel2.icon")); // NOI18N
        jcMousePanel2.setName("jcMousePanel2"); // NOI18N

        bt_agregar.setIcon(resourceMap.getIcon("bt_agregar.icon")); // NOI18N
        bt_agregar.setText(resourceMap.getString("bt_agregar.text")); // NOI18N
        bt_agregar.setName("bt_agregar"); // NOI18N
        bt_agregar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                bt_agregarActionPerformed(evt);
            }
        });

        bt_modificar.setIcon(resourceMap.getIcon("bt_modificar.icon")); // NOI18N
        bt_modificar.setText(resourceMap.getString("bt_modificar.text")); // NOI18N
        bt_modificar.setEnabled(false);
        bt_modificar.setName("bt_modificar"); // NOI18N
        bt_modificar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                bt_modificarActionPerformed(evt);
            }
        });

        bt_eliminar.setIcon(resourceMap.getIcon("bt_eliminar.icon")); // NOI18N
        bt_eliminar.setText(resourceMap.getString("bt_eliminar.text")); // NOI18N
        bt_eliminar.setEnabled(false);
        bt_eliminar.setName("bt_eliminar"); // NOI18N
        bt_eliminar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                bt_eliminarActionPerformed(evt);
            }
        });

        bt_limpiar.setIcon(resourceMap.getIcon("bt_limpiar.icon")); // NOI18N
        bt_limpiar.setText(resourceMap.getString("bt_limpiar.text")); // NOI18N
        bt_limpiar.setName("bt_limpiar"); // NOI18N
        bt_limpiar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                bt_limpiarActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jcMousePanel2Layout = new javax.swing.GroupLayout(jcMousePanel2);
        jcMousePanel2.setLayout(jcMousePanel2Layout);
        jcMousePanel2Layout.setHorizontalGroup(
            jcMousePanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jcMousePanel2Layout.createSequentialGroup()
                .addGroup(jcMousePanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(bt_modificar, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(bt_eliminar, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(bt_limpiar, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(bt_agregar, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        jcMousePanel2Layout.setVerticalGroup(
            jcMousePanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jcMousePanel2Layout.createSequentialGroup()
                .addComponent(bt_agregar)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(bt_modificar)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(bt_eliminar)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(bt_limpiar)
                .addContainerGap(87, Short.MAX_VALUE))
        );

        jcMousePanel3.setBorder(javax.swing.BorderFactory.createTitledBorder(null, resourceMap.getString("jcMousePanel3.border.title"), javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, resourceMap.getFont("jcMousePanel3.border.titleFont"), resourceMap.getColor("jcMousePanel3.border.titleColor"))); // NOI18N
        jcMousePanel3.setIcon(resourceMap.getIcon("jcMousePanel3.icon")); // NOI18N
        jcMousePanel3.setName("jcMousePanel3"); // NOI18N

        scroll.setName("scroll"); // NOI18N

        dtm.addColumn("Código");
        dtm.addColumn("Cédula");
        dtm.addColumn("Nombre");
        dtm.addColumn("Tipo");
        dtm.addColumn("Dirección");
        dtm.addColumn("Teléfono");
        dtm.addColumn("e-mail");
        tabalproveedor.setAutoCreateRowSorter(true);
        tabalproveedor.setAutoResizeMode(javax.swing.JTable.AUTO_RESIZE_OFF);
        tabalproveedor.setCellSelectionEnabled(true);
        tabalproveedor.setDragEnabled(true);
        tabalproveedor.setEnabled(false);
        tabalproveedor.setName("tabalproveedor"); // NOI18N
        scroll.setViewportView(tabalproveedor);

        javax.swing.GroupLayout jcMousePanel3Layout = new javax.swing.GroupLayout(jcMousePanel3);
        jcMousePanel3.setLayout(jcMousePanel3Layout);
        jcMousePanel3Layout.setHorizontalGroup(
            jcMousePanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(scroll, javax.swing.GroupLayout.DEFAULT_SIZE, 430, Short.MAX_VALUE)
        );
        jcMousePanel3Layout.setVerticalGroup(
            jcMousePanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(scroll, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 262, Short.MAX_VALUE)
        );

        bt_buscar.setIcon(resourceMap.getIcon("bt_buscar.icon")); // NOI18N
        bt_buscar.setText(resourceMap.getString("bt_buscar.text")); // NOI18N
        bt_buscar.setName("bt_buscar"); // NOI18N
        bt_buscar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                bt_buscarActionPerformed(evt);
            }
        });

        tx_buscar.setText(resourceMap.getString("tx_buscar.text")); // NOI18N
        tx_buscar.setName("tx_buscar"); // NOI18N
        tx_buscar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                tx_buscarActionPerformed(evt);
            }
        });

        cb_buscarproveedor.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Código", "CC o NIT", "Nombre" }));
        cb_buscarproveedor.setName("cb_buscarproveedor"); // NOI18N

        jcMousePanel4.setIcon(resourceMap.getIcon("jcMousePanel4.icon")); // NOI18N
        jcMousePanel4.setName("jcMousePanel4"); // NOI18N

        javax.swing.GroupLayout jcMousePanel4Layout = new javax.swing.GroupLayout(jcMousePanel4);
        jcMousePanel4.setLayout(jcMousePanel4Layout);
        jcMousePanel4Layout.setHorizontalGroup(
            jcMousePanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 447, Short.MAX_VALUE)
        );
        jcMousePanel4Layout.setVerticalGroup(
            jcMousePanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 46, Short.MAX_VALUE)
        );

        javax.swing.GroupLayout pisoProveedorLayout = new javax.swing.GroupLayout(pisoProveedor);
        pisoProveedor.setLayout(pisoProveedorLayout);
        pisoProveedorLayout.setHorizontalGroup(
            pisoProveedorLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(pisoProveedorLayout.createSequentialGroup()
                .addGroup(pisoProveedorLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(pisoProveedorLayout.createSequentialGroup()
                        .addGap(202, 202, 202)
                        .addComponent(jcMousePanel4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(pisoProveedorLayout.createSequentialGroup()
                        .addContainerGap()
                        .addGroup(pisoProveedorLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                            .addGroup(javax.swing.GroupLayout.Alignment.LEADING, pisoProveedorLayout.createSequentialGroup()
                                .addComponent(cb_buscarproveedor, javax.swing.GroupLayout.PREFERRED_SIZE, 90, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(tx_buscar))
                            .addGroup(javax.swing.GroupLayout.Alignment.LEADING, pisoProveedorLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                .addComponent(bt_buscar)
                                .addGroup(pisoProveedorLayout.createSequentialGroup()
                                    .addComponent(jcMousePanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                    .addComponent(jcMousePanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jcMousePanel3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        pisoProveedorLayout.setVerticalGroup(
            pisoProveedorLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, pisoProveedorLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jcMousePanel4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(31, 31, 31)
                .addGroup(pisoProveedorLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jcMousePanel3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(pisoProveedorLayout.createSequentialGroup()
                        .addGroup(pisoProveedorLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(tx_buscar, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(cb_buscarproveedor, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(bt_buscar)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(pisoProveedorLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jcMousePanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jcMousePanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))))
                .addGap(42, 42, 42))
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(pisoProveedor, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(pisoProveedor, javax.swing.GroupLayout.PREFERRED_SIZE, 394, javax.swing.GroupLayout.PREFERRED_SIZE)
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void bt_agregarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_bt_agregarActionPerformed
        try {
            if(tx_codigo.getText().trim().equals("") || tx_codigo.getText().trim().equals("") ||
                tx_cedula.getText().trim().equals("") || tx_nombre.getText().trim().equals("") ||
                tx_direccion.getText().trim().equals("") || tx_telefono.getText().trim().equals("") ||
                tx_email.getText().trim().equals("") || (cb_tipo.getSelectedIndex()==0)){
                JOptionPane.showMessageDialog(null,"Asegurece de llear todos los campos.");
            }
            boolean e = ControlValidacion.validaEmail(tx_email);
            boolean t = ControlValidacion.validaNumero(tx_telefono, 11);
            boolean c = ControlValidacion.validaNumero(tx_cedula, 45);          
            if(e && t && c){
                Proveedor pro = new Proveedor();
                pro.setCodigoProvee(tx_codigo.getText());
                pro.setCedula(tx_cedula.getText());
                pro.setNombre(tx_nombre.getText());
                pro.setDireccion(tx_direccion.getText());
                pro.setTelefono(tx_telefono.getText());
                pro.setEmail(tx_email.getText());
                pro.setTipo(cb_tipo.getSelectedItem().toString());
                ControlProveedor.agregarProveedor(pro);
                limpiar();
                listarProveedor();
                JOptionPane.showMessageDialog(null,"Proveedor guardado con exito!.");
            }else{
                e = ControlValidacion.validaEmail(tx_email);
                t = ControlValidacion.validaNumero(tx_telefono, 11);
                c = ControlValidacion.validaNumero(tx_cedula, 15);
                JOptionPane.showMessageDialog(null,"digite bien los datos");
            }
        } catch (SQLException ex) {
            Logger.getLogger(vistaProveedor.class.getName()).log(Level.SEVERE, null, ex);
        } catch (Exception ex) {
            Logger.getLogger(vistaProveedor.class.getName()).log(Level.SEVERE, null, ex);
        }
    }//GEN-LAST:event_bt_agregarActionPerformed

    private void bt_modificarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_bt_modificarActionPerformed
        try {
            if(tx_codigo.getText().trim().equals("") || tx_codigo.getText().trim().equals("") ||
                tx_cedula.getText().trim().equals("") || tx_nombre.getText().trim().equals("") ||
                tx_direccion.getText().trim().equals("") || tx_telefono.getText().trim().equals("") ||
                tx_email.getText().trim().equals("") || (cb_tipo.getSelectedIndex()==0)){
                JOptionPane.showMessageDialog(null,"Asegurece de llear todos los campos.");
            }
            boolean e = ControlValidacion.validaEmail(tx_email);
            boolean t = ControlValidacion.validaNumero(tx_telefono, 11);
            boolean c = ControlValidacion.validaNumero(tx_cedula, 45);
            if(e && t && c){
                Proveedor pro = new Proveedor();
                pro.setCodigoProvee(tx_codigo.getText());
                pro.setCedula(tx_cedula.getText());
                pro.setNombre(tx_nombre.getText());
                pro.setDireccion(tx_direccion.getText());
                pro.setTelefono(tx_telefono.getText());
                pro.setEmail(tx_email.getText());
                pro.setTipo(cb_tipo.getSelectedItem().toString());
                ControlProveedor.ModificarProveedor(pro,tx_codigo.getText());
                limpiar();
                listarProveedor();
                JOptionPane.showMessageDialog(null,"Proveedor guardado con exito!.");
            }else{
                e = ControlValidacion.validaEmail(tx_email);
                t = ControlValidacion.validaNumero(tx_telefono, 11);
                c = ControlValidacion.validaNumero(tx_cedula, 15);
                JOptionPane.showMessageDialog(null,"digite bien los datos");
            }
        } catch (SQLException ex) {
            Logger.getLogger(vistaProveedor.class.getName()).log(Level.SEVERE, null, ex);
        } catch (Exception ex) {
            Logger.getLogger(vistaProveedor.class.getName()).log(Level.SEVERE, null, ex);
        }
    }//GEN-LAST:event_bt_modificarActionPerformed

    private void bt_limpiarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_bt_limpiarActionPerformed
        limpiar();
        listarProveedor();
    }//GEN-LAST:event_bt_limpiarActionPerformed

    private void bt_eliminarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_bt_eliminarActionPerformed
        jd_eliminarProveedor.setSize(350, 150);
        jd_eliminarProveedor.setLocation(350, 300);
        jd_eliminarProveedor.setVisible(true);
    }//GEN-LAST:event_bt_eliminarActionPerformed

    private void bt_jdEliminarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_bt_jdEliminarActionPerformed
        try {
            ControlProveedor.EliminarProveedor(tx_codigo.getText());
            limpiar();
            listarProveedor();
        } catch (SQLException ex) {
            Logger.getLogger(vistaProveedor.class.getName()).log(Level.SEVERE, null, ex);
        } catch (Exception ex) {
            Logger.getLogger(vistaProveedor.class.getName()).log(Level.SEVERE, null, ex);
        }
      jd_eliminarProveedor.setVisible(false);
      JOptionPane.showMessageDialog(null,"Proveedor eliminado con exito!.");
    }//GEN-LAST:event_bt_jdEliminarActionPerformed

    private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed
      jd_eliminarProveedor.setVisible(false);
    }//GEN-LAST:event_jButton2ActionPerformed

    private void bt_buscarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_bt_buscarActionPerformed
        buscar();        // TODO add your handling code here:
    }//GEN-LAST:event_bt_buscarActionPerformed

    private void tx_nombreFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_tx_nombreFocusLost
        tx_nombre.setText(tx_nombre.getText().trim().toUpperCase());
    }//GEN-LAST:event_tx_nombreFocusLost

    private void tx_direccionFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_tx_direccionFocusLost
        tx_direccion.setText(tx_direccion.getText().trim().toUpperCase());
    }//GEN-LAST:event_tx_direccionFocusLost

    private void tx_emailFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_tx_emailFocusLost
       tx_email.setText(tx_email.getText().trim().toLowerCase());
    }//GEN-LAST:event_tx_emailFocusLost

    private void tx_buscarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_tx_buscarActionPerformed
       this.buscar();
    }//GEN-LAST:event_tx_buscarActionPerformed
        public void limpiar(){

                tx_cedula.setText("");
                tx_nombre.setText("");
                tx_direccion.setText("");
                tx_telefono.setText("");
                tx_email.setText("");
                cb_buscarproveedor.setSelectedIndex(0);
                bt_modificar.setEnabled(false);
                bt_eliminar.setEnabled(false);
                bt_agregar.setEnabled(true);
            }
        public void buscar(){
        String item = cb_buscarproveedor.getSelectedItem().toString();
        Proveedor pro;
        try {
            if(tx_buscar.getText().trim().equals("")){
                JOptionPane.showMessageDialog(null,"Por favor digite un criterio de busqueda.");
            }else{
                if(item.equals("Código")){
                 pro = ControlProveedor.BuscarProveedor(tx_buscar.getText());
                }else{
                    if(item.equals("CC o NIT")){
                    pro = ControlProveedor.BuscarProveedorCed(tx_buscar.getText());
                    }else{
                        pro = ControlProveedor.BuscarProveedorNom(tx_buscar.getText());
                    }
                }
                if(pro != null){
                    tx_codigo.setText(pro.getCodigoProvee());
                    tx_cedula.setText(pro.getCedula());
                    tx_nombre.setText(pro.getNombre());
                    tx_direccion.setText(pro.getDireccion());
                    tx_telefono.setText(pro.getTelefono());
                    tx_email.setText(pro.getEmail());
                    bt_modificar.setEnabled(true);
                    bt_eliminar.setEnabled(true);
                    bt_agregar.setEnabled(false);
                    tx_buscar.setText("");
                }else{
                    JOptionPane.showMessageDialog(null,"Proveedor no encontrado.");
                }
            }
            } catch (SQLException ex) {
                Logger.getLogger(vistaProveedor.class.getName()).log(Level.SEVERE, null, ex);
            }
    }

        public void listarProveedor(){
        Proveedor pro = new Proveedor();
        try {
            dtm.setNumRows(0);
            ControlProveedor.listarProveedor();
            Iterator it = ControlProveedor.getProveedor().iterator();
                while (it.hasNext()) {
                    pro = (Proveedor) it.next();
                    String[] fila = {pro.getCodigoProvee(), pro.getCedula(), pro.getNombre(), pro.getTipo(), pro.getDireccion(), pro.getTelefono(), pro.getEmail()};
                    dtm.addRow(fila);
                }
            DecimalFormat formateador = new DecimalFormat("000");
            if(pro.getCodigoProvee()==null){
                tx_codigo.setText(formateador.format(1));
            }else{
                int contador_pro =Integer.parseInt(pro.getCodigoProvee());
                contador_pro+=1;
                tx_codigo.setText(formateador.format(contador_pro));
            }
        } catch (SQLException ex) {
            Logger.getLogger(vistaProveedor.class.getName()).log(Level.SEVERE, null, ex);
        } catch (Exception ex) {
            Logger.getLogger(vistaProveedor.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    /**
    * @param args the command line arguments
    */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
            }
        });
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton bt_agregar;
    private javax.swing.JButton bt_buscar;
    private javax.swing.JButton bt_eliminar;
    private javax.swing.JButton bt_jdEliminar;
    private javax.swing.JButton bt_limpiar;
    private javax.swing.JButton bt_modificar;
    private javax.swing.JComboBox cb_buscarproveedor;
    private javax.swing.JComboBox cb_tipo;
    private javax.swing.JButton jButton2;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private jcMousePanel.jcMousePanel jcMousePanel1;
    private jcMousePanel.jcMousePanel jcMousePanel2;
    private jcMousePanel.jcMousePanel jcMousePanel3;
    private jcMousePanel.jcMousePanel jcMousePanel4;
    private javax.swing.JDialog jd_eliminarProveedor;
    public static jcMousePanel.jcMousePanel pisoProveedor;
    private javax.swing.JScrollPane scroll;
    private javax.swing.JTable tabalproveedor;
    private javax.swing.JTextField tx_buscar;
    private javax.swing.JTextField tx_cedula;
    private javax.swing.JTextField tx_codigo;
    private javax.swing.JTextField tx_direccion;
    private javax.swing.JTextField tx_email;
    private javax.swing.JTextField tx_nombre;
    private javax.swing.JTextField tx_telefono;
    // End of variables declaration//GEN-END:variables

}
